﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PayrollHR.Web;
using Payroll.Common.Utils;
using Payroll.BusinessLogic;
using Payroll.BusinessLogic.Directory;
using Payroll.BusinessLogic.CustomerManager;
using Payroll.BusinessLogic.Utils;
using MigraDoc.DocumentObjectModel;

namespace PayrollHR.Administration.Modules
{
    public partial class CustomerInfoControl : BasePayrollAdministrationUserControl
    {
        public int CustomerID
        {
            get
            {
                return CommonHelper.QueryStringInt("CustomerId");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }
        }
        public void FillDropDown()
        {
            FillCustTypeDropDowns();
        }
        /// <summary>
        /// Binds the customer.
        /// </summary>
        /// <param name="item">The item.</param>
        public void BindCustomer(Customer item)
        {
            if (CommonHelper.IsNull(item))
                return;
            txtCustName.Text = item.CustName;
            txtCustPhone.Text = item.CustPhoneNumber;
            txtTaxcode.Text = item.CustTaxCode;
            txtEmailSend.Text = item.CustEmail;
            txtContact.Text = item.CustContact;
            txtAdress.Text = item.CustAddress;
            txtCustMobile.Text = item.CustMobile;
            txtCustPhone.Text = item.CustPhoneNumber;
            ddlCustType.Items.FindByValue(CommonHelper.ToString(item.CustType)).Selected = true;
        }
        private void FillCustTypeDropDowns()
        {
            ddlCustType.Items.Clear();
            var customertypeColection = this.CustomerService.GetCustomerType();
            customertypeColection.Insert(0, new CutomerType { CutomerTypeId = 0, CutomerTypeName = "----None----" });
            foreach (var customertype in customertypeColection)
            {
                ListItem ddlCustTypeItem2 = new ListItem(customertype.CutomerTypeName, customertype.CutomerTypeId.ToString());
                ddlCustType.Items.Add(ddlCustTypeItem2);
            }
        }
        public Customer GetCustomer()
        {
            int UserId = PayrollContext.Current.Session.EmployeeId;
            Customer customer = new Customer
            {
                CustomerId = this.CustomerID > 0 ? this.CustomerID : 0,
                CustName = txtCustName.Text.Trim(),
                CustAddress = txtAdress.Text.Trim(),
                CustType = CommonHelper.ToInteger(ddlCustType.SelectedItem.Value),
                CustContact = txtContact.Text.Trim(),
                CustTaxCode = txtTaxcode.Text.Trim(),
                CustEmail = txtEmailSend.Text.Trim(),
                CustMobile = txtCustMobile.Text.Trim(),
                CustPhoneNumber = txtCustPhone.Text,
                Createby = UserId,
                Modified = UserId,
                CreateDate = DateTime.Now,
                ModifiedDate = DateTime.Now
            };
            return customer;
        }
    }
}